Nldouapp.onPageInit('Discover',function () {
    if($$('.view-main').data('page')==='Discover') {
        var title = '一问奕答';
        var desc = '复旦大学社会学教授沈奕斐，为您解答家庭教育的各类问题，陪您共走育儿路';
        setShare(title,Share_url,desc);
    }

    getDiscoverData(GetDiscoverData_url);
    getQuestion(1,GetDiscoverQuestion_url,true);
    getNotifyCount(GetNotifyCount_url);

    $$('#Discover .infinite-scroll').on('infinite', function () {
        if (discoverloading) return;
        discoverloading = true;
        var lastIndex = parseInt($$("#Discover .qlist .qitem").length);
        var page = lastIndex/discoverpagesize + 1;
        getQuestion(page,GetDiscoverQuestion_url,true);
    });
}).trigger();
Nldouapp.onPageInit('Notify',function(){
    //分类显示未读消息数量
    var uhtml = Nldouapp.Notifyicon2Template({unread:Usermsgnum});
    var shtml = Nldouapp.Notifyicon2Template({unread:Sysmsgnum});
    $$('.notifynav .notifylisticon').remove();
    $$('.notifynav .unotifylistbtn').append(uhtml);
    $$('.notifynav .sysnotifylistbtn').append(shtml);
    //获取未读用户消息
    getUserNotify(GetUserNotify_url,1,true);
    $$('#Notify .infinite-scroll').on('infinite', function () {
        if (notifyloading) return;
        notifyloading = true;
        var list = $$("#Notify .notifylistwrap");
        var lastIndex = parseInt(list.find('li').length);
        var page = lastIndex/notifypagesize + 1;
        var listtype = list.data('type');
        switch (listtype){
            case 'user':
                getUserNotify(GetUserNotify_url,page,true);
                break;
            case 'sys':
                getSysNotify(GetSysNotify_url,page,true);
                break;
        }
    });
});
Nldouapp.onPageAfterBack('Notify',function(){
    getNotifyCount(GetNotifyCount_url);
});
Nldouapp.onPageInit('Subject',function (page) {
    var sid = page.query.sid;
    $$('#Subject').data('id',sid);
    getSubById(GetSubByid_url,sid);
    getQuestionBysid(GetQBySid_url,1,sid,'score',true);
    getNotifyCount(GetNotifyCount_url);

    $$('#Subject .infinite-scroll').on('infinite', function () {
        if (subjectloading) return;
        subjectloading = true;
        var sort = $$(this).data('sort');
        var lastIndex = parseInt($$("#Subject .qlist .qitem").length);
        var page = lastIndex/subjectpagesize + 1;
        getQuestionBysid(GetQBySid_url,page,sid,sort,true);
    });
});
Nldouapp.onPageAfterBack('Subject',function(){
    var shareobj = getShareContent();
    setShare(shareobj.title,shareobj.url,shareobj.desc);
});
Nldouapp.onPageInit('Question',function(page){
    var qid = page.query.qid;
    $$('#Question').data('id',qid);

    getQuestionById(qid,GetQuestionQdetail_url);
    getAnswerByQid(qid,1,GetQuestionAitem_url,'score',true);
    getNotifyCount(GetNotifyCount_url);
    readQuestion(AddQuestionViews_url,qid);

    $$('#Question .infinite-scroll').on('infinite', function () {
        if (questionloading) return;
        questionloading = true;
        var sort = $$(this).data('sort');
        var lastIndex = parseInt($$("#Question .answerlist .aitem").length);
        var page = lastIndex/questionpagesize + 1;
        getAnswerByQid(qid,page,GetQuestionAitem_url,sort,true);
    });
});
Nldouapp.onPageAfterBack('Question',function(){
    var shareobj = getShareContent();
    setShare(shareobj.title,shareobj.url,shareobj.desc);
});
Nldouapp.onPageInit('Beansrank',function (page) {
    var qid = page.query.qid;
    getBeansrankByqid(Beansrank_url,1,qid);
    $$('#Beansrank .infinite-scroll').on('infinite',function () {
        if (rankloading) return;
        rankloading = true;
        var lastIndex = parseInt($$("#Beansrank .beansranklist li").length);
        var page = lastIndex/rankpagesize + 1;
        getBeansrankByqid(Beansrank_url,page,qid);
        rankloading = false;
    });
});
Nldouapp.onPageInit('Questionrank',function (page){
    if($$('.view-main').data('page')==='Questionrank') {
        var title = '一问奕答女神榜';
        var desc = '您的朋友邀请您，为他困扰的问题贡献一份力哦~~';
        var url = Share_url + '&page=questionrank';
        setShare(title, url, desc);
    }

    getQrank(Qrank_url,1);
    $$('#Questionrank .infinite-scroll').on('infinite', function () {
        if (qrankloading) return;
        qrankloading = true;
        var list = $$("#Questionrank .qlistwrap");
        var lastIndex = parseInt(list.find('a').length);
        var page = lastIndex/rankpagesize + 1;
        var listtype = list.data('type');
        switch (listtype){
            case 'rank':
                getQrank(Qrank_url,page);
                break;
            case 'res':
                getQresponsed(Qresponsed_url,page,true);
                break;
        }
    });
});
Nldouapp.onPageAfterBack('Questionrank',function(){
    var shareobj = getShareContent();
    setShare(shareobj.title,shareobj.url,shareobj.desc);
});
Nldouapp.onPageInit('Answer',function(page){
    var aid = page.query.aid;
    $$('#Answer').data('id',aid);
    getAnswerById(aid,GetAnwserAdetail_url);
    getCommentsByAid(aid,1,GetAnswerCitem_url,'score',true);

    $$('#Answer .infinite-scroll').on('infinite', function () {
        if (answerloading) return;
        answerloading = true;
        var sort = $$(this).data('sort');
        var lastIndex = parseInt($$("#Answer .commentlist .citem").length);
        var page = lastIndex/answerpagesize + 1;
        getCommentsByAid(aid,page,GetAnswerCitem_url,sort,true);
    });
});
Nldouapp.onPageAfterBack('Answer',function(){
    var shareobj = getShareContent();
    setShare(shareobj.title,shareobj.url,shareobj.desc);
});
Nldouapp.onPageInit('Response',function (page) {
    var cid = page.query.cid;
    var aid = page.query.aid;
    var rnavhtml = Nldouapp.ResponsnavTemplate({aid:aid});
    $$('.responsenav').html(rnavhtml);
    getResponseByCid(cid,1,GetCommentsResponse_url);

    $$('#Response .infinite-scroll').on('infinite',function () {
        if (responseloading) return;
        responseloading = true;
        var lastIndex = parseInt($$("#Response .response-wrap li").length);
        var page = lastIndex/responsepagesize + 1;
        getResponseByCid(cid,page,GetCommentsResponse_url);
    });
});
Nldouapp.onPageInit('Ucenter',function () {
    if($$('.view-main').data('page')==='Ucenter') {
        var title = '一问奕答';
        var desc = '复旦大学社会学教授沈奕斐，为您解答家庭教育的各类问题，陪您共走育儿路';
        setShare(title,Share_url,desc);
    }
    getUcInfo(GetUcenterInfo_url);
    getNotifyCount(GetNotifyCount_url);
});
Nldouapp.onPageAfterBack('Ucenter',function(){
    var shareobj = getShareContent();
    setShare(shareobj.title,shareobj.url,shareobj.desc);
});
Nldouapp.onPageInit('Chargebeans',function () {
    getChargeUser(Chargeuser_url);
});
Nldouapp.onPageInit('Dechargebeans',function () {
    getDechargeUser(Chargeuser_url);
});
Nldouapp.onPageInit('Myfollows',function () {
    getMyfollowq(GetMyfollowq_url,1,true);
    $$('#Myfollows .infinite-scroll').on('infinite', function () {
        if (myfollowsloading) return;
        myfollowsloading = true;
        var list = $$("#Myfollows .followlist");
        var lastIndex = parseInt(list.find('a').length);
        var page = lastIndex/myfollowspagesize + 1;
        var listtype = list.data('type');
        switch (listtype){
            case 'question':
                getMyfollowq(GetMyfollowq_url,page,true);
                break;
            case 'subject':
                getMyfollowsub(GetMyfollowsub_url,page,true);
                break;
        }
    });
});
Nldouapp.onPageInit('Mycollects',function () {
    getMycollect(GetMycollect_url,1,true);
    $$('#Mycollects .infinite-scroll').on('infinite', function () {
        if (mycollectsloading) return;
        mycollectsloading = true;
        var list = $$("#Mycollects .collectlist");
        var lastIndex = parseInt(list.find('.aitem').length);
        var page = lastIndex/mycollectspagesize + 1;
        getMycollect(GetMycollect_url,page,true);
    });
});
Nldouapp.onPageInit('Myanswers',function () {
    getMyanswer(GetMyanswer_url,1,true);
    $$('#Myanswers .infinite-scroll').on('infinite', function () {
        if (myanswerloading) return;
        myanswerloading = true;
        var list = $$("#Myanswers .myanswerlist");
        var lastIndex = parseInt(list.find('.aitem').length);
        var page = lastIndex/myanswerpagesize + 1;
        getMyanswer(GetMyanswer_url,page,true);
    });
});
Nldouapp.onPageInit('Myquestions',function () {
    getMyquestion(GetMyquestion_url,1,true);

    $$('#Myquestions .infinite-scroll').on('infinite', function () {
        if (myquestionloading) return;
        myquestionloading = true;
        var list = $$("#Myquestions .myqlist");
        var lastIndex = parseInt(list.find('.qitem').length);
        var page = lastIndex/myquestionpagesize + 1;
        getMyquestion(GetMyquestion_url,page,true);
    });
});
Nldouapp.onPageInit('Profile',function () {
    getProfile();
});
Nldouapp.onPageInit('Childinfo',function () {
    Nldouapp.calendar({
        input:'#cbcal',
        monthNames:['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'],
        weekHeader:false,
        closeOnSelect:true
    });
    $$('.subchild').on('click',function () {
        var cgender = $$('select[name="childgender"]').val();
        var cg = cgender=='m'?'男孩':'女孩';
        var cbirth = $$('input[name="childbirth"]').val();
        var cschool = $$('select[name="childschool"]').val();
        var cs = cschool=='1'?'公立学校':(cschool=='2'?'私立学校':'国际学校');
        var data = [{id:0,gender:cgender,school:cschool,birthDay:cbirth,genderstr:cg,schoolstr:cs}];
        var html = Nldouapp.ChilditemTemplate(data);
        $$('#Profile .child-wrap').append(html);
        mainView.router.back();
    });
});
